/**
 * 
 */
package org.neptune.service.util;

import javax.websocket.Session;

import org.apache.commons.lang3.StringUtils;
import org.apache.shiro.SecurityUtils;
import org.neptune.api.entity.SeckillUser;
import org.neptune.common.constant.NeptuneConstant;

/**
 * @author liuwenlai
 *
 */
public class WebUtil {

	public static SeckillUser getLoginUser() {
		SeckillUser user = (SeckillUser) SecurityUtils.getSubject().getPrincipal();

		return user;
	}

	public static String getUserName(SeckillUser user) {
		if (user == null) {
			return null;
		}
		return user.getUsername();
	}

	public static String getNickName(SeckillUser user) {
		if (user == null) {
			return null;
		}
		if (StringUtils.isNoneBlank(user.getNickName())) {
			return user.getNickName();
		}
		return user.getUsername();
	}

	public static SeckillUser getWebsocketUser(Session session) {
		SeckillUser user = (SeckillUser) session.getUserProperties()
				.get(NeptuneConstant.WEBSOCKET_USER);
		return user;
	}

}
